# -*- coding: utf-8 -*-
# @Time    : 2022/1/11 20:58
# @Author  : 魏福齐
# @Email   : 775776913@qq.com
# @File    : page_caiwu_skd.py
# @Software: PyCharm

from pages.base_page import BasePage
from selenium.webdriver.common.by import By

class CaiwuPageSkd(BasePage):
    '''收款单页面类'''
    add_skd_submit_locator = (
    By.CSS_SELECTOR, 'body > div.container > div.row > div:nth-child(1) > div.pull-right > a:nth-child(2)')
    #【添加收款单】按钮
    skd_fuzeren_ok_locator=(By.XPATH,'/html/body/div[8]/div[3]/div/button[1]')
    skd_fuzeren_input_locator = (By.CSS_SELECTOR, '#owner_name')
    # 负责人输入框
    skd_fuzeren_tbody_locator = (By.CSS_SELECTOR, '#d_content')
    # 选择负责人table的tbody
    guanlian_ysk_locator = (By.CSS_SELECTOR, '#receivables')
    #应收款输入框
    gl_ysk_table_locator = (By.CSS_SELECTOR, '#data')
    #应收款table
    gl_ysk_ok_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]')
    #应收款table的【ok】按钮
    skd_sk_price_locator = (By.CSS_SELECTOR, '#money')
    #收款单金额
    skd_miaoshu_input_locator = (By.CSS_SELECTOR,
                                 'body > div.container > div.row > div > form > table > tbody > tr:nth-child(8) >'
                                 ' td:nth-child(2) > textarea')
    #收款单描述
    yijiezhang_submit_locator = (By.CSS_SELECTOR,
                                 'body > div.container > div.row > div > form > table > tbody > tr:nth-child(7) > '
                                 'td:nth-child(2) > input[type=radio]:nth-child(2)')
    #已结账按钮
    skd_lst_table_locator = (By.CSS_SELECTOR, 'body > div.container > div.row > div:nth-child(2) > table > tbody')
    #收款单页面tbody
    huishouzhan_skd_locator = (By.CSS_SELECTOR, 'body > div.container > p > a:nth-child(17)')
    #【回收站】按钮
    shanchu_chenggong_text=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')
    #删除成功断言文本
    skd_pay_time_input_locator = (By.CSS_SELECTOR, '#pay_time')
    #收款单收款时间
    skd_lst_page_locator = (By.XPATH, '/html/body/div[5]/div[1]/ul/li[3]/a')
    #收款单列表页面


    def add_skd(self):
        '''【添加收款单】按钮'''
        self.driver.find_element(*self.add_skd_submit_locator).click()


    def skd_fuzeren_check(self,fuzeren):
        self.driver.find_element(*self.skd_fuzeren_input_locator).click()
        # 点击负责人选择框
        table = self.driver.find_element(*self.skd_fuzeren_tbody_locator)
        trs = table.find_elements(By.TAG_NAME, 'tr')
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[1].text == fuzeren:
                tds[0].find_element(By.TAG_NAME, 'input').click()
        # 选中负责人
        self.driver.find_element(*self.skd_fuzeren_ok_locator).click()
        # 点击【ok】

    def guanlian_ysk(self,yskname):
        '''选择应收款'''
        self.driver.find_element(*self.guanlian_ysk_locator).click()
        # 选择应收款关联
        table = self.driver.find_element(*self.gl_ysk_table_locator)
        trs = table.find_elements(By.TAG_NAME, 'tr')
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[1].text == yskname:
                tds[0].find_element(By.TAG_NAME, 'input').click()
                break
        # 选择应收款
        self.driver.find_element(*self.gl_ysk_ok_locator).click()
        # 点击【ok】

    def skd_price(self,price):
        '''输入收款单金额'''
        self.driver.find_element(*self.skd_sk_price_locator).clear()
        # 清空收款金额
        self.driver.find_element(*self.skd_sk_price_locator).send_keys(price)
        # 输入收款金额

    def skd_time(self,time):
        self.driver.find_element(*self.skd_pay_time_input_locator).send_keys(time)
        # 输入收款时间

    def skd_miaoshu(self,miaoshu):
        '''输入收款单描述'''
        self.driver.find_element(*self.skd_miaoshu_input_locator).send_keys(miaoshu)

    def skd_lst_name_duanyan(self):
        '''获取收款单table的应收款名文本'''
        table = self.driver.find_element(*self.skd_lst_table_locator)
        # 获取应收款列表
        trs = table.find_elements(By.TAG_NAME, 'tr')
        for tr in trs:
            tds = tr.find_elements(By.TAG_NAME, 'td')
            return tds[2].text

    def yijiezhang(self):
        '''点击已结账'''
        self.driver.find_element(*self.yijiezhang_submit_locator).click()

    def jump_skd(self):
        '''跳转到收款单列表页面'''
        self.driver.find_element(*self.skd_lst_page_locator).click()

    def check_skd(self,skdname):
        '''选中要删除的收款单'''
        table = self.driver.find_element(*self.skd_lst_table_locator)
        # 获取收款单table
        trs = table.find_elements(By.TAG_NAME, 'tr')
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[2].text == skdname:
                tds[0].find_element(By.TAG_NAME, 'input').click()

    def huishouzhan(self):
        '''点击【回收站】'''
        self.driver.find_element(*self.huishouzhan_skd_locator).click()

